package com.study.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.study.constant.ApiRouterConstant;
import com.study.convention.result.Result;
import com.study.convention.result.Results;
import com.study.dto.req.RecycleBinPageReqDTO;
import com.study.dto.req.RecycleBinReqDTO;
import com.study.dto.resp.ShortLinkPageRespDTO;
import com.study.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author canace
 * @version 1.0
 * @description 短链接回收站控制器
 * @date 2024/2/4 11:27
 */

@RestController
@RequiredArgsConstructor
@RequestMapping(ApiRouterConstant.BASE_API_V1_RECYCLE_BIN)
public class RecycleBinController {

    private final RecycleBinService recycleBinService;

    /**
     * 将短链接移动至回收站
     *
     * @param requestParam 请求参数
     * @return 结果
     */
    @PostMapping("/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinReqDTO requestParam) {
        recycleBinService.saveRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 分页显示回收站中短链接信息
     *
     * @param requestParam 请求参数
     * @return 回收站中短链接信息
     */
    @GetMapping("/page")
    public Result<IPage<ShortLinkPageRespDTO>> getRecycleBinPage(RecycleBinPageReqDTO requestParam) {
        return Results.success(recycleBinService.getRecycleBinPage(requestParam));
    }

    /**
     * 恢复回收站中的短链接
     *
     * @param requestParam 请求参数
     * @return 结果
     */
    @PostMapping("/recover")
    public Result<Void> recoverRecycleBin(@RequestBody RecycleBinReqDTO requestParam) {
        recycleBinService.recoverRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 删除回收站中的短链接
     *
     * @param requestParam 请求参数
     * @return 结果
     */
    @PostMapping("/remove")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinReqDTO requestParam) {
        recycleBinService.removeRecycleBin(requestParam);
        return Results.success();
    }
}
